#include <iostream>
#include <string>

#include "Log.hpp"
#include "EpollServer.hpp"
#include "Connection.hpp"
#include "Listener.hpp"
using namespace LogMudule;

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cout << "Usage: " << argv[0] << " port" << std::endl;
        return 1;
    }
    ENABLE_CONSOLE_LOG();
    uint16_t port = std::stoi(argv[1]);
    EpollServer epoll_svr;

    // 完成具体工作的模块,也有一个listensockfd
    Listener listen(port);
    // 我们要把listensockfd，封装成为一个Connection，Connection托管给EpollServer
    auto conn = Factory::BuildConnection(listen.Sockfd(), EPOLLIN | EPOLLET,[&listen]()
                 { listen.Accept(); }, nullptr, nullptr);

    epoll_svr.InsertConnection(conn);
    epoll_svr.Loop();
    return 0;
}